package com.cysyz.mylib.io.dirgenerator.impl;

import com.cysyz.mylib.io.dirgenerator.IDirGenerator;
import com.cysyz.mylib.utils.MyStringUtils;

/**
 * Created by emall on 2014/8/27.
 */
public abstract class AbstarctDirGenerator implements IDirGenerator {
    public String generate(String prefixDir, String postfixDir) {
        if (!MyStringUtils.hasText(prefixDir)) {
            prefixDir = "";
        }
        StringBuilder dirBuilder = new StringBuilder(prefixDir);
        dirBuilder.append("/");
        String dir = generateMiddleDir();
        dirBuilder.append(dir);
        if (MyStringUtils.hasText(postfixDir)) {
            dirBuilder.append("/");
            dirBuilder.append(postfixDir);
        }
        return dirBuilder.toString();
    }

    @Override
    public String generate() {
        return this.generate("", "");
    }

    protected abstract String generateMiddleDir();
}
